package pool.book;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Properties;

/**
 * @Author Administrator
 * @Date 2020/5/26 15:40
 **/
public class JDBCUtils {

    private static DataSource ds;

    static {
        try {

            Properties pro=new Properties();
            pro.load(JDBCUtils.class.getClassLoader().getResourceAsStream("druid.properties"));

        }catch (Exception e){
            e.printStackTrace();
        }


    }

    public static DataSource getDataSource() {
        return ds;
    }
    public static Connection getConnection() throws Exception{
        return ds.getConnection();
    }

    public static void close(Statement stmt, Connection conn){
        try {
            if (stmt!=null){
                stmt.close();
            }
            if (conn!=null){
            conn.close();
            }

        }catch (Exception e){
            e.printStackTrace();
        }

    }
    public static void close(ResultSet rs, Statement stmt, Connection conn){
        try {
            if (rs!=null){
                rs.close();
            }
            if (stmt!=null){
                stmt.close();
            }
            if (conn!=null){
                conn.close();
            }

        }catch (Exception e){
            e.printStackTrace();
        }

    }
}
